/*
 * @Author : Grit<dooms21day@163.com>
 * @Company : 成都慧创智通信息技术有限公司
 * @Brand : 企慧蚁
 * @Copyright : 2021-
*/
odoo.define("iant_list_view_manager.many2one_link", function(require) {
    "use strict";

    var ListFieldMany2One = require("web.relational_fields").ListFieldMany2One;

    ListFieldMany2One.include({
        _renderReadonly: function() {
            this._super(...arguments);
            var self = this;

            if (!this.noOpen && this.value) {
                this.$el.removeClass("o_form_uri");
                this.$el = $("<span/>", {
                    html: this.$el.html(),
                    class: this.$el.attr("class") + " o_field_text",
                    name: this.$el.attr("name"),
                });

                var $a = $("<a/>", {
                    href: "#",
                    class:
                        "o_form_uri btn" +
                        " fa fa-arrow-circle-o-right",
                }).on("click", function(ev) {
                    ev.preventDefault();
                    ev.stopPropagation();

                    self.do_action({
                        type: "ir.actions.act_window",
                        res_model: self.field.relation,
                        res_id: self.value.res_id,
                        views: [[false, "form"]],
                        target: "target"
                    });
                });
                this.$el.append($a);
            }
        }
    });
});
